﻿namespace LogManager.Core.Factories
{
    using System.Xml.Linq;
    using LogManager.Core.Models;
    using LogManager.Core.Models.Smtp;
    using LogManager.Core.Providers;
    using LogManager.Utils.Unity;
    using Microsoft.Practices.Unity;

    public class XmlElementFactory : XmlElementFactoryBase, IXmlElementFactory
    {
        public override IXmlTemplateProvider TemplateProvider { get; protected set; }

        public readonly IUnityContainer _container;

        public XmlElementFactory(IUnityContainer container, IXmlTemplateProvider templateProvider)
        {
            this._container = container;
            this.TemplateProvider = templateProvider;
        }

        public override Location CreateLocation(XElement baseNode, IServer parent)
        {
            return this._container.Resolve<XElement, IServer, Location>(baseNode, parent);
        }

        public override Server CreateServer(XElement baseNode, IPlateform parent)
        {
            return this._container.Resolve<XElement, IPlateform, Server>(baseNode, parent);
        }

        public override Plateform CreatePlateform(XElement baseNode, IWarehouse parent)
        {
            return this._container.Resolve<XElement, IWarehouse, Plateform>(baseNode, parent);
        }

        public override Warehouse CreateWarehouse(XElement baseNode, IConfiguration parent)
        {
            return this._container.Resolve<XElement, IConfiguration, Warehouse>(baseNode, parent);
        }

        public override Configuration CreateConfiguration(XDocument baseDocument)
        {
            return this._container.Resolve<XDocument, Configuration>(baseDocument);
        }

        public override Settings CreateSettings(XElement baseNode)
        {
            return this._container.Resolve<XElement, Settings>(baseNode);
        }

        public override SmtpSettings CreateSmtpSettings(XElement baseNode)
        {
            return this._container.Resolve<XElement, SmtpSettings>(baseNode);
        }

        public override SmtpServer CreateSmtpServer(XElement baseNode)
        {
            return this._container.Resolve<XElement, SmtpServer>(baseNode);
        }

        public override From CreateSmtpFrom(XElement baseNode)
        {
            return this._container.Resolve<XElement, From>(baseNode);
        }

        public override To CreateSmtpTo(XElement baseNode)
        {
            return this._container.Resolve<XElement, To>(baseNode);
        }
    }
}
